package com.xrtn.controller;

import com.xrtn.ApiVersion;
import com.xrtn.bean.SysVersionInfo;
import com.xrtn.service.IDoctorService;
import com.xrtn.utils.CodeEnum;
import com.xrtn.utils.ObjUtils;
import com.xrtn.utils.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by tu_pei on 2018/2/27.
 */
@Api("商户验证相关接口")
@Controller
@RequestMapping("/{version}/index")
public class DesktopController {

    @Autowired
    private IDoctorService doctorService;

    /**
     * @Title: desktop
     * @Description: 首页
     * @param @param userId
     * @param @return
     * @return ResponseData
     * @throws
     */
    @ApiOperation(value = "首页",notes="首页")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name="userId",dataType="int",required=true,value="用户id",defaultValue = "1"),
            @ApiImplicitParam(paramType="query",name="bookingDate",dataType="string",required=true,value="预约日期",defaultValue = "2018-02-27")
    })
    @RequestMapping(value = "/desktop",method = RequestMethod.POST)
    @ApiVersion(1)
    @ResponseBody
    public ResponseData desktop(Integer userId,String bookingDate){

        // 创建响应Model
        ResponseData data = new ResponseData();
        // 调用Service
        Map<String, Object> resultMap = doctorService.desktop(userId,bookingDate);
        // 设置返回对象

        Map<String, Object> resultMaps = new HashMap<>();
        resultMaps.put("userInfo",resultMap.get("userInfo"));
        resultMaps.put("bookingList",resultMap.get("bookingList"));
        resultMaps.put("subclinicInfo",resultMap.get("subclinicInfo"));

        data.setResults(resultMaps);
        // 返回数据
        return data;
    }

    /**
     * @Title: existNewVersion
     * @Description: 判断是否为最新版本
     * @param @param userId
     * @param @return
     * @return ResponseData
     * @throws
     */
    @ApiOperation(value = "判断是否为最新版本",notes="判断是否为最新版本")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name="versionCode",dataType="int",required=true,value="版本code",defaultValue = "0"),
            @ApiImplicitParam(paramType="query",name="equipmentType",dataType="int",required=true,value="设备类型：0：安卓；1：ios",defaultValue = "1")
    })
    @RequestMapping(value = "/existNewVersion",method = RequestMethod.POST)
    @ApiVersion(1)
    @ResponseBody
    public ResponseData existNewVersion(SysVersionInfo versionInfo){

        // 创建响应Model
        ResponseData data = new ResponseData();
        // 调用Service
        versionInfo = doctorService.existNewVersion(versionInfo);
        Map<String,Object> retMap = new HashMap<>();
        if(ObjUtils.isEmpty(versionInfo)){
            retMap.put("versionInfo", null);
        }else{
            retMap.put("versionInfo", versionInfo);
        }
        // 设置返回对象
        data.setResults(retMap);
        // 返回数据
        return data;
    }
}
